package com.yd.app.mapper.provider;

import com.yd.domain.searchParam.DicParam;
import org.springframework.util.StringUtils;

import java.util.Map;

/**
 * @author zy
 * @create 2018-03-07 17:45
 * @desc
 **/
public class DicProvider extends BaseProvider {
    /**
     * @Author: zy
     * @Desc:查询数据列表
     * @Date:  2018/3/7
     */
    public String searchDicList(Map map){
        DicParam dicParam= (DicParam) map.get("dicParam");
        StringBuilder sb=new StringBuilder("SELECT dic.`code`,dic.des,dic.id,dic.title,dic.type from sys_dic dic " +
                "WHERE 1=1 ");
        sb.append(createSearchSanWhereSql(dicParam));
        sb.append("  limit #{startRow},#{pageSize}");
        return sb.toString();
    }
    /**
     * @Author: zy
     * @Desc:查询数据
     * @Date:  2018/3/7
     */
    public String searchDicCount(Map map){
        DicParam dicParam= (DicParam) map.get("dicParam");
        StringBuilder sb=new StringBuilder("SELECT COUNT(1) from sys_dic dic  " +
                "  where 1=1 ");
        sb.append(createSearchSanWhereSql(dicParam));
        return sb.toString();
    }
    /**
     * @Author: zy
     * @Desc:权限查询条件
     * @Date:  2018/3/7
     */
    private String createSearchSanWhereSql(DicParam dicParam){
        StringBuilder sb=new StringBuilder();
        if(!StringUtils.isEmpty(dicParam.getTitle())){
            sb.append(" and dic.title like  '%"+dicParam.getTitle()+"%'  ");
        }
        if(!StringUtils.isEmpty(dicParam.getCode())){
            sb.append(" and dic.`code` = '"+dicParam.getCode()+"'  ");
        }
        if(!StringUtils.isEmpty(dicParam.getType())){
            sb.append(" and dic.type = '"+dicParam.getType()+"'  ");
        }
        return sb.toString();
    }
}
